package com.tuanbiao.dialog;

import android.content.Context;
import android.view.Gravity;

import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatTextView;

import com.tuanbiao.R;
import com.tuanbiao.widget.ClearEditText;

/**
 * @author abiao
 * @since 2022/5/6 17:56
 */
public class ResetDialog {
    public static final class Builder
            extends BaseDialog.Builder<Builder> {
        private OnResetClickListener mListener;
        private AppCompatTextView tvTitle;
        private AppCompatImageView ivClose;
        private ClearEditText etInput;
        private AppCompatButton btnReset;
        private AppCompatButton btnConfirm;

        public Builder(Context context) {
            super(context);
            setAnimStyle(BaseDialog.ANIM_TOAST);
            setBackgroundDimEnabled(true);
            setCancelable(false);

            setContentView(R.layout.dialog_reset);
            setGravity(Gravity.CENTER);

            tvTitle = (AppCompatTextView) findViewById(R.id.tv_title);
            ivClose = (AppCompatImageView) findViewById(R.id.iv_close);
            etInput = (ClearEditText) findViewById(R.id.et_input);
            btnReset = (AppCompatButton) findViewById(R.id.btn_reset);
            btnConfirm = (AppCompatButton) findViewById(R.id.btn_confirm);

            ivClose.setOnClickListener(view -> {
                if (null != mListener) mListener.onClose(getDialog());
                dismiss();
            });
            btnConfirm.setOnClickListener(view -> {
                if (null != mListener)
                    mListener.onConfirm(etInput.getText().toString(), getDialog());
            });
            btnReset.setOnClickListener(view -> {
                if (null != mListener) {
                    mListener.onReset(this);
                }
            });
        }

        public Builder setListener(OnResetClickListener listener) {
            mListener = listener;
            return this;
        }

        public Builder setTitle(String title) {
            if (null != tvTitle) tvTitle.setText(title);
            return this;
        }

        public Builder setInput(String input) {
            if (null != etInput) etInput.setText(input);
            return this;
        }

    }

    public interface OnResetClickListener {
        void onConfirm(String content, BaseDialog dialog);

        void onReset(Builder builder);

        void onClose(BaseDialog dialog);
    }
}
